package com.liu.resume.ui.presenter;

import android.content.Context;
import android.util.Log;

import com.liu.resume.ui.contract.BaseContract;

import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 类、方法注释 仅用来做个演示
 * @author creat  by:yts 2016/9/29
 * @author update by:
 *
 */

public class TestPresenter implements BaseContract.TestPresenter, Observer {
    private Context mContext;
    private BaseContract.TestView mTestView;
    private Subscription subscribe;
    private Subscription subscription;

    public TestPresenter(Context context, BaseContract.TestView view) {
        mContext = context;
        mTestView = view;
        view.setPresenter(this);
    }

    @Override
    public void subscribe(Observer observer) {
        subscription = Observable.just(1, 2, 3, 4)
                .subscribeOn(Schedulers.io()) // 指定 subscribe() 发生在 IO 线程
                .observeOn(AndroidSchedulers.mainThread()) // 指定 Subscriber 的回调发生在主线程
                .subscribe(observer);
    }


    @Override
    public void unSubscribe() {
        subscription.unsubscribe();
    }


    @Override
    public void onDestroy() {
        mTestView = null;
        unSubscribe();
    }


    @Override
    public void onCompleted() {
        Log.e("onCompleted", "onCompleted");
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onNext(Object o) {
        Log.e("Object", "" + o.toString());
    }
}
